package com.sdsy.blockchaintrainingback.controller.user;

import com.sdsy.blockchaintrainingback.pojo.common.CommonResult;
import com.sdsy.blockchaintrainingback.service.user.AuthService;
import com.sdsy.blockchaintrainingback.vo.auth.AuthLoginReqVO;
import com.sdsy.blockchaintrainingback.vo.auth.AuthLoginRespVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.web.bind.annotation.*;

import static com.sdsy.blockchaintrainingback.pojo.common.CommonResult.success;

/**
 * @Description 认证
 * @Author linzili
 * @Date 2023/9/24 16:27
 * @Version 1.0
 */

@Tag(name = "认证")
@RestController
@RequestMapping("/auth")
public class AuthController {

    @Resource
    private AuthService authService;

    @PostMapping("/login")
    @Operation(summary="使用账号密码登陆")
    public CommonResult<AuthLoginRespVO> login(@RequestBody @Valid AuthLoginReqVO reqVO) {
        return success(authService.login(reqVO));
    }

    @GetMapping("/register")
    @Operation(summary = "注册账号")
    public String register(String password) {
        return new BCryptPasswordEncoder().encode(password);
    }
}
